module(
    name = "rules_kotlin",
    version = "1.8.1",
    compatibility_level = 1,
    repo_name = "rules_kotlin",
)

bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_java", version = "7.6.5")
bazel_dep(name = "rules_python", version = "0.23.1")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_android", version = "0.1.1")

rules_kotlin_extensions = use_extension("//src/main/starlark/core/repositories:bzlmod_setup.bzl", "rules_kotlin_extensions")
use_repo(
    rules_kotlin_extensions,
    "com_github_google_ksp",
    "com_github_jetbrains_kotlin",
    "com_github_jetbrains_kotlin_git",
    "com_github_pinterest_ktlint",
    "kotlinx_serialization_core_jvm",
    "kotlinx_serialization_json",
    "kotlinx_serialization_json_jvm",
    "released_rules_kotlin",
)

# Once the released rules_koltin is defined, configure it.
rules_kotlin_bootstrap_extensions = use_extension(
    "//src/main/starlark/core/repositories:bzlmod_bootstrap.bzl",
    "rules_kotlin_bootstrap_extensions",
)
use_repo(
    rules_kotlin_bootstrap_extensions,
    "released_com_github_google_ksp",
    "released_com_github_jetbrains_kotlin",
)

register_toolchains("@released_rules_kotlin//kotlin/internal:default_toolchain")

# Back to the regularly scheduled configuration.
register_toolchains("//kotlin/internal:default_toolchain")

# TODO(bencodes) We should be able to remove this once rules_android has rolled out official Bzlmod support
remote_android_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")

# Development dependencies
# TODO(bencodes) A bunch of these dependencies need to be marked as dev_dependencies but before we can do that
# we need to sort out a few cases around how these rules are consumed in various ways.

bazel_dep(name = "rules_jvm_external", version = "5.3")
bazel_dep(name = "bazel_ci_rules", version = "1.0.0")

rbe_preconfig = use_repo_rule("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")

rbe_preconfig(
    name = "buildkite_config",
    toolchain = "ubuntu2004",
)

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
    name = "kotlin_rules_maven",
    artifacts = [
        "com.google.code.findbugs:jsr305:3.0.2",
        "junit:junit:4.13-beta-3",
        "com.google.protobuf:protobuf-java:3.6.0",
        "com.google.protobuf:protobuf-java-util:3.6.0",
        "com.google.guava:guava:27.1-jre",
        "com.google.truth:truth:0.45",
        "com.google.auto.service:auto-service:1.1.1",
        "com.google.auto.service:auto-service-annotations:1.1.1",
        "com.google.auto.value:auto-value:1.10.1",
        "com.google.auto.value:auto-value-annotations:1.10.1",
        "com.google.dagger:dagger:2.51",
        "com.google.dagger:dagger-compiler:2.51",
        "com.google.dagger:dagger-producers:2.51",
        "javax.annotation:javax.annotation-api:1.3.2",
        "javax.inject:javax.inject:1",
        "org.apache.commons:commons-compress:1.26.2",
        "org.pantsbuild:jarjar:1.7.2",
        "dev.zacsweers.autoservice:auto-service-ksp:jar:1.2.0",
        "com.squareup.moshi:moshi:1.15.1",
        "com.squareup.moshi:moshi-kotlin:1.15.1",
        "com.squareup.moshi:moshi-kotlin-codegen:1.15.1",
    ],
    fail_if_repin_required = True,
    fetch_sources = True,
    lock_file = "//:kotlin_rules_maven_install.json",
    repositories = [
        "https://maven-central.storage.googleapis.com/repos/central/data/",
        "https://maven.google.com",
        "https://repo1.maven.org/maven2",
    ],
)
maven.override(
    name = "override_target_in_deps_kotlin_stdlib",
    coordinates = "org.jetbrains.kotlin.kotlin:kotlin-stdlib",
    target = "@rules_kotlin//kotlin/compiler:kotlin-stdlib",
)
maven.override(
    name = "override_target_in_deps_kotlin_stdlib_jdk7",
    coordinates = "org.jetbrains.kotlin.kotlin:kotlin-stdlib-jdk7",
    target = "@rules_kotlin//kotlin/compiler:kotlin-stdlib-jdk7",
)
maven.override(
    name = "override_target_in_deps_kotlin_stdlib_jdk8",
    coordinates = "org.jetbrains.kotlin.kotlin:kotlin-stdlib-jdk8",
    target = "@rules_kotlin//kotlin/compiler:kotlin-stdlib-jdk8",
)
use_repo(maven, "kotlin_rules_maven", "unpinned_kotlin_rules_maven")

bazel_dep(name = "rules_pkg", version = "0.7.0")
bazel_dep(name = "stardoc", version = "0.7.0", repo_name = "io_bazel_stardoc")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")

bazel_dep(name = "rules_testing", version = "0.5.0", dev_dependency = True)
bazel_dep(name = "rules_bazel_integration_test", version = "0.25.0", dev_dependency = True)

bazel_binaries = use_extension("@rules_bazel_integration_test//:extensions.bzl", "bazel_binaries", dev_dependency = True)
bazel_binaries.download(version_file = "//:.bazelversion")
bazel_binaries.download(version = "6.4.0")
bazel_binaries.download(version = "8.0.0-pre.20240206.3")
use_repo(
    bazel_binaries,
    "bazel_binaries",
    "bazel_binaries_bazelisk",
    "build_bazel_bazel_.bazelversion",
    "build_bazel_bazel_6_4_0",
    "build_bazel_bazel_8_0_0-pre_20240206_3",
)
